// component/timeSelectPop/timeSelectPop.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      default: false
    },
    type:{
     type:String,
     value:""
    },
    //年月日就传date
    timeType: {
      type: String,
      value: "datetime"
    },
    minDate: {
      type: Number,
      value: new Date().getTime()
    },
    maxDate: {
      type: Number,
      value: new Date(2022, 12, 31).getTime(),
    },
    currentDate: {
      type: Number,
      value: new Date().getTime()
    }

  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    clickCenterPopupOverlay() {
      this.triggerEvent('popHide', { show: false });
    },
    //时间确认选择:
    hideDatePicker(e) {
      // console.log("JJLog:时间确认选择是:" + JSON.stringify(e));
      let timeSt = "";
      timeSt = this.timestampToTime(e.detail);
      // console.log("JJLog:看看这个timeSt是:" + timeSt);
      this.triggerEvent('timeSelectSure', { timeStr: timeSt,type:this.properties.type });
    },
    selectDatePciker(e) {
      // console.log("JJLog:时间确认选择是:" + JSON.stringify(e));
    },
    timestampToTime(timestamp) {
      var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
      var Y = date.getFullYear() + '-';
      var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
      var D = date.getDate() + ' ';
      var h = date.getHours() + ':';
      var m = date.getMinutes() + ':';
      var s = date.getSeconds();
      if (D < 9) {
        D = "0" + D;
      }
      if (h < 9) {
        h = "0" + h;
      }
      if (m < 9) {
        m = "0" + m;
      }
      if (s < 9) {
        s = "0" + s;
      }
      if (this.properties.timeType == "date") {
        return Y + M + D;
      } else {
        return Y + M + D + h + m + s;
      }

    }

  }
})
